import { message } from "antd";

const downloadFile = (data, fileName) => {
    // new Blob 实例化文件流

    const url = window.URL.createObjectURL(
      new Blob(data, {
        type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
      }),
    );
    const link = document.createElement('a');
    link.style.display = 'none';
    link.href = url;
    link.setAttribute('download', fileName);
    document.body.appendChild(link);
    link.click();
    //下载完成移除元素
    document.body.removeChild(link);
    //释放掉blob对象
    window.URL.revokeObjectURL(url);
  };

const haneleExport = async (response,title) => {
  try {
    downloadFile([response], `${title}${new Date().getTime()}.xlsx`);
  } catch (error) {
    message.error("导出失败");
  }
};

export default haneleExport;